#ifndef DOKERPROCESSOR_H
#define DOKERPROCESSOR_H

#include <QtCore/qthread.h>
#include <QtScript/qscriptengine.h>

class DokerModel;
class PageObject;
class TextObject;

class DokerProcessor : public QThread
{
    Q_OBJECT
public:
    explicit DokerProcessor(DokerModel *model, QObject *parent = 0);
    ~DokerProcessor();
    DokerModel *model() { return m_model; }
    QScriptEngine *engine() { return &m_engine; }
    QScriptValue runScript(const QString &fileName);
    bool hasFunction(const QString &functionName);
    QScriptValue runFunction(const QString &functionName,
                             const QScriptValueList &arguments = QScriptValueList());
    void setGlobalFunction(QScriptEngine::FunctionSignature signature,
                           const QString &functionName);
    void restoreGlobalFunctions();

    PageObject *addPage(const QString &style, const QScriptValueList &arguments);
    TextObject *addText(const QString &style, const QString &content, const QScriptValueList &arguments);

signals:
    void pageAdded(PageObject *page);
    void textAdded(TextObject *text);
    
private slots:


protected:
    void run();

private:
    void clear();

private:
    DokerModel      *m_model;
    QScriptEngine    m_engine;

    QList<PageObject*>   m_pages;
    PageObject      *m_contextPage;

    QList<TextObject*>   m_texts;
};


#endif // DOKERPROCESSOR_H
